<template>
  <div>
    <van-nav-bar title="我的收获地址" left-text="返回" left-arrow @click-left="Edit" />
    <van-address-list
      v-model="chosenAddressId"
      :list="list"
      default-tag-text="默认"
      @add="onAdd"
      @edit="onEdit"
      @click-item="onclick"
    />
  </div>
</template>

<script>
export default {
  data() {
    return {
      chosenAddressId: "1",
      list: [],
    };
  },
  methods: {
    Edit() {
      this.$router.replace("/user");
    },
    // 新增
    onAdd() {
      this.$router.replace("/addRaegion");
    },
    // 编辑
    onEdit(item) {
      console.log(item);
      this.Sto.Session.set("address", item);
      this.$router.replace("/Edit");
    },
    // 获取
    async getshow() {
      let res = await this.$post(this.url + "contect/", {
        userId: this.$store.state.user.id,
      });
      if (res.errorCode == "0") {
        res.data.contectList.map((nus) => {
          nus.tel = nus.mobile;
          nus.isDefault = nus.contactFlag == 1;
          this.list.push(nus);
        });

        for (const i of res.data.contectList) {
          if (i.contactFlag == 1) {
            this.chosenAddressId = i.id;
          }
        }
      }
    },
    onclick(item, index) {
      console.log(item);
      this.Sto.Session.set("payaddress", item);
      if (this.Sto.Session.get("bools")) {
        this.$router.replace("/zhifu")
      } else {
        return
      }
    }
  },
  created() {
    this.getshow();
  },
};
</script>

<style  scoped>
</style>